﻿using System;
using System.Collections.Generic;
using System.Linq;

using Microsoft.Xna.Framework.Input;


namespace WorldOnFire
{
    class CLobbySkirmish : ABCLobby
    {
        private enum eOptions
        {
            DIFFICULTY,
            WAVES,
            RESOURCES,
            LEVEL,
            MODIFIERS_,
            EXIT,
            COUNT
        };

        private enum eExpandableOptions
        {
            MODIFIERS,
            COUNT
        };

        //private int m_nStartingResources;
       // private int m_nWaveCount;

        public override void Initialize()
        {
            // Set the option values
            //m_nStartingResources = 500;
            //m_nWaveCount = 10;

            // Initialize the options
            m_nOptionCount = (int)eOptions.COUNT;
            m_strOptionTitles = new string[(int)eOptions.COUNT] 
            {
                "Difficulty",
                "Wave Count",
                "Starting Resources",
                "Selected Level",
                "Modifiers",
                "Exit"
            };

            // Initialize the expandable options
            m_nExpandableOptionCount = (int)eExpandableOptions.COUNT;
            m_ExpandableOptions = new tExpandableOption[(int)eExpandableOptions.COUNT];
            m_nExpandableOptionIndices = new int[(int)eExpandableOptions.COUNT]
            {
                (int)eOptions.MODIFIERS_
            };

            // Set the data for each expandable option
            m_ExpandableOptions[(int)eExpandableOptions.MODIFIERS].nOptionCount = (int)CSettings.eModifiers.COUNT;
            m_ExpandableOptions[(int)eExpandableOptions.MODIFIERS].strOptionTitles = new string[(int)CSettings.eModifiers.COUNT]
            {
                "Wild Waves",
                "Short-Range Sensors",
                "No Spare Change",
                "Double Time",
                "Juggernaut"
            };

            base.Initialize();
        }

        public override void Input(float _fDeltaTime)
        {
            // TODO: FUCKING INPUT. JESUS CHRIST.

            if(SInputManager.IsKeyPressed(Keys.Enter) == true)
            {
                switch( m_nSelectedIndex )
                {
                    case (int)eOptions.DIFFICULTY:
                    case (int)eOptions.WAVES:
                    case (int)eOptions.RESOURCES:
                        {
                            // Toggle whether the selected option is active
                            m_bSelectionActive = !m_bSelectionActive;
                        }
                        break;
                    case (int)eOptions.LEVEL:
                        {
                            // TODO: GO TO LEVEL SELECTION
                        }
                        break;
                    case (int)eOptions.MODIFIERS_:
                        {
                            // If the selection is expanded,
                            if( m_bSelectionExpanded == true )
                            {
                                // Toggle the currently selected modifier
                                CSettings.ToggleModifier((CSettings.eModifiers)m_ExpandableOptions[(int)eExpandableOptions.MODIFIERS].nSelectedIndex);
                            }
                            // If the selection is not expanded
                            else
                            {
                                // Expand it
                                m_bSelectionExpanded = true;
                            }
                        }
                        break;
                    case (int)eOptions.EXIT:
                        {
                            s_StateManager.Switch(new CMenuMain());
                        }
                        break;
                }
            }


            // TODO: HANDLE UP/DOWN INPUT

            base.Input(_fDeltaTime);
        }
    }
}
